package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Cart;
import com.fantastic.model.pojo.zjs.OrderDetails;
import com.fantastic.service.zjs.CartService;
import com.fantastic.service.zjs.OrderDetailsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/6 11:14
 * @description: 订单详情信息请求控制器
 */
@RestController
@RequestMapping("/orderDetails")
public class OrderDetailsControllerAdmin {

    @Resource
    private OrderDetailsService orderDetailsService;

    /**
     * 查询所有订单详情信息
     *
     * @param orderDetails
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listOrderDetails")
    public ResultData listOrderDetails(OrderDetails orderDetails, @RequestParam(name = "page",
            defaultValue = "1") int pageNum,
                                       @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderDetails> list = orderDetailsService.listOrderDetails(orderDetails);
        PageInfo<OrderDetails> PageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, PageInfo);
    }

    /**
     * 查询单个订单详情信息
     *
     * @param orderDetailsId
     * @return
     */
    @GetMapping("/getOrderDetails")
    public ResultData getCart(Integer orderDetailsId) {
        return new ResultData(RespStatusInfo.OK, orderDetailsService.getOrderDetails(orderDetailsId));
    }

    /**
     * 添加订单详情信息
     *
     * @param orderDetails
     * @return
     */
    @PostMapping("/insertOrderDetails")
    public ResultData insertOrderDetails(OrderDetails orderDetails) {
        return new ResultData(RespStatusInfo.OK, orderDetailsService.insertOrderDetails(orderDetails));
    }

    /**
     * 修改订单详情信息
     *
     * @param orderDetails
     * @return
     */
    @PostMapping("/updateOrderDetails")
    public ResultData updateOrderDetails(OrderDetails orderDetails) {
        return new ResultData(RespStatusInfo.OK, orderDetailsService.updateOrderDetails(orderDetails));
    }


    /**
     * 删除订单详情信息
     *
     * @param orderDetailsId
     * @return
     */
    @PostMapping("/deleteOrderDetails")
    public ResultData deleteOrderDetails(Integer orderDetailsId) {
        return new ResultData(RespStatusInfo.OK, orderDetailsService.deleteOrderDetails(orderDetailsId));
    }


}
